package com.example.dryyzx.dao;

import com.example.dryyzx.entity.Checkout;
import org.apache.ibatis.jdbc.SQL;

public class CheckoutSqlProvider {
    public String insertSelective(Checkout record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("checkout");
        
        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=INTEGER}");
        }
        
        if (record.getCustomerId() != null) {
            sql.VALUES("customer_id", "#{customerId,jdbcType=INTEGER}");
        }
        
        if (record.getType() != null) {
            sql.VALUES("type", "#{type,jdbcType=CHAR}");
        }

        if (record.getReason() != null) {
            sql.VALUES("reason", "#{reason,jdbcType=VARCHAR}");
        }
        
        if (record.getCheckoutTime() != null) {
            sql.VALUES("checkout_time", "#{checkoutTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getApplyTime() != null) {
            sql.VALUES("apply_time", "#{applyTime,jdbcType=TIMESTAMP}");
        }

        if (record.getApprovalTime() != null) {
            sql.VALUES("approval_time", "#{approvalTime,jdbcType=TIMESTAMP}");
        }

        if (record.getApprover() != null) {
            sql.VALUES("approver", "#{approver,jdbcType=VARCHAR}");
        }

        if (record.getLeaveStatus() != null) {
            sql.VALUES("leave_status", "#{leaveStatus,jdbcType=CHAR}");
        }
        
        if (record.getRemarks() != null) {
            sql.VALUES("remarks", "#{remarks,jdbcType=VARCHAR}");
        }
        
        if (record.getEnable() != null) {
            sql.VALUES("enable", "#{enable,jdbcType=BIT}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(Checkout record) {
        SQL sql = new SQL();
        sql.UPDATE("checkout");
        
        if (record.getCustomerId() != null) {
            sql.SET("customer_id = #{customerId,jdbcType=INTEGER}");
        }
        
        if (record.getType() != null) {
            sql.SET("type = #{type,jdbcType=CHAR}");
        }

        if (record.getReason() != null) {
            sql.SET("reason = #{reason,jdbcType=VARCHAR}");
        }
        
        if (record.getCheckoutTime() != null) {
            sql.SET("checkout_time = #{checkoutTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getApplyTime() != null) {
            sql.SET("apply_time = #{applyTime,jdbcType=TIMESTAMP}");
        }

        if (record.getApprovalTime() != null) {
            sql.SET("approval_time = #{approvalTime,jdbcType=TIMESTAMP}");
        }

        if (record.getApprover() != null) {
            sql.SET("approver = #{approver,jdbcType=VARCHAR}");
        }

        if (record.getLeaveStatus() != null) {
            sql.SET("leave_status = #{leaveStatus,jdbcType=CHAR}");
        }
        
        if (record.getRemarks() != null) {
            sql.SET("remarks = #{remarks,jdbcType=VARCHAR}");
        }
        
        if (record.getEnable() != null) {
            sql.SET("enable = #{enable,jdbcType=BIT}");
        }
        
        sql.WHERE("id = #{id,jdbcType=INTEGER}");
        
        return sql.toString();
    }
}